﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;

namespace SSISFromCode.Events
{
    internal class PackageEvents : DefaultEvents
    {

        private ImportMessages _messages;

        public PackageEvents( ImportMessages messages )
        {
            _messages = messages;
        }

        //public override void OnBreakpointHit( IDTSBreakpointSite breakpointSite, BreakpointTarget breakpointTarget )
        //{
        //    ;
        //}

        //public override void OnCustomEvent( TaskHost taskHost, string eventName, string eventText, ref object[] arguments, string subComponent, ref bool fireAgain )
        //{
        //    ;
        //}

        public override bool OnError( DtsObject source, int errorCode, string subComponent, string description, string helpFile, int helpContext, string idofInterfaceWithError )
        {
            _messages.Add( IMPORT_MESSAGES.ERROR, subComponent, description );
            return true;
        }

        //public override void OnExecutionStatusChanged( Executable exec, DTSExecStatus newStatus, ref bool fireAgain )
        //{
        //    ;
        //}

        public override void OnInformation( DtsObject source, int informationCode, string subComponent, string description, string helpFile, int helpContext, string idofInterfaceWithError, ref bool fireAgain )
        {
            _messages.Add( IMPORT_MESSAGES.INFORMATION, subComponent, description );
            fireAgain = true;
        }

        //public override void OnPostExecute( Executable exec, ref bool fireAgain )
        //{
        //    ;
        //}

        //public override void OnPostValidate( Executable exec, ref bool fireAgain )
        //{
        //    ;
        //}

        //public override void OnPreExecute( Executable exec, ref bool fireAgain )
        //{
        //    Console.WriteLine("OnPreExecute");
        //}

        //public override void OnPreValidate( Executable exec, ref bool fireAgain )
        //{
        //    ;
        //}

        /// <summary>
        /// This is what I got importing over 300K records.
        /// Thus, package events are unrelated to the Data Task Flow events.
        /// </summary>
        /// Validating,iicent Conplete:ø
        //Ualidating. Percent Conplete:5ø
        //Ualidating. Percent Conplete:1øø
        //Ualidating. Percent Conplete:ø
        //Ualidating. Percent Conplete:5ø
        //Ualidating. Percent Conplete:1øø
        //Prepare for Execute, Percent Conplete:ø
        //Prepare for Execute, Percent Complete:50
        //Prepare for Execute, Percent Complete:1øø
        //Pre—Execute, Percent Complete:ø
        //Pre—Execute. Percent Conplete:5ø
        //Pre—Execute. Percent Complete:100
        //Post Execute, Percent Conplete:0
        //Post Execute, Percent Conplete:5ø
        //Post Execute, Percent Conplete:1øø
        //Cleanup. Percent Conplete:ø
        //Cleanup. Percent Conplete:5ø
        //Cleanup. Percent Conplete:100
        public override void OnProgress( TaskHost taskHost, string progressDescription, int percentComplete, int progressCountLow, int progressCountHigh, string subComponent, ref bool fireAgain )
        {
            /// This package progress is forking useless; it always reports the exact same thing.
            //_messages.Add( IMPORT_MESSAGES.PROGRESS, subComponent, progressDescription, Convert.ToString( percentComplete ) );
            fireAgain = false;
        }

        //public bool OnQueryCancel()
        //{
        //    return true;
        //}

        public override void OnTaskFailed( TaskHost taskHost )
        {
            _messages.Add( IMPORT_MESSAGES.FAILURE, taskHost.Name );
        }

        //public override void OnVariableValueChanged( DtsContainer DtsContainer, Variable variable, ref bool fireAgain )
        //{
        //    ;
        //}

        //public override void OnWarning( DtsObject source, int warningCode, string subComponent, string description, string helpFile, int helpContext, string idofInterfaceWithError )
        //{
        //    ;
        //}
    }
}
